import type { IFieldProps, IConfigProps } from '@/components/sofastui/AdvancedTable/interface'
import type { FormRule } from '@form-create/element-ui'

export const fields: IFieldProps[] = [
  {
    label: 'ID',
    prop: 'id',
    minWidth: 60,
    import: true,
    export: true,
    search: true,
  },
  {
    label: '模板编码',
    prop: 'code',
    minWidth: 60,
    import: true,
    export: true,
    search: true,
  },
  {
    label: '邮箱厂商',
    prop: 'firm.name',
    minWidth: 60,
    import: true,
    export: true,
    search: true,
  },
  {
    label: '模板主题',
    prop: 'templateTheme',
    minWidth: 60,
    import: true,
    export: true,
    search: true,
  },
  {
    label: '描述',
    prop: 'desc',
    minWidth: 60,
    import: true,
    export: true,
    search: true,
  },
  {
    label: '创建时间',
    prop: 'createdAt',
    minWidth: 60,
    import: true,
    export: true,
    search: true,
  },
  {
    label: '修改时间',
    prop: 'updatedAt',
    minWidth: 60,
    import: true,
    export: true,
    search: true,
  },
]

export const config: IConfigProps = {
  name: 'sysEmailTemplateTable',
  rowKey: 'id',
  url: '/api/sys/email_template',
  selection: true,
  add: true,
  delete: true,
  expand: true,
  showIndex: true,
  import: true,
  export: true,
  search: true,
  advancedSearch: true,
  refresh: true,
  settings: true,
}

export const formRules: FormRule = [
  {
    type: 'select',
    field: 'firmId',
    title: '邮箱厂商',
    effect: {
      fetch: {
        parse:
          '[[FORM-CREATE-PREFIX-function (res, rule, api){\nif(res.code === 200) return res.data.map(i=>({label:i.name,value:i.id}));\nreturn [];\n}-FORM-CREATE-SUFFIX]]',
        beforeFetch: '',
        onError: '',
        to: 'options',
        action: '/api/sys/email_firm',
        method: 'GET',
        dataType: 'json',
        headers: {},
        query: {},
        data: {},
      },
    },
    $required: true,
    props: {
      _optionType: 3,
      clearable: true,
    },
    _fc_id: 'id_Fwh5mc35zbnbchc',
    name: 'firmId',
    display: true,
    hidden: false,
    _fc_drag_tag: 'select',
    col: {
      span: 12,
    },
  },
  {
    type: 'input',
    field: 'code',
    title: '模板编码',
    $required: true,
    props: {
      placeholder: '请输入模板编码',
    },
    _fc_id: 'id_Fja7mc21xer3xlc',
    name: 'code',
    display: true,
    hidden: false,
    _fc_drag_tag: 'input',
    col: {
      span: 12,
    },
  },
  {
    type: 'input',
    field: 'templateTheme',
    title: '邮件主题',
    $required: true,
    props: {
      placeholder: '请输入邮件主题',
    },
    _fc_id: 'id_Fja7mc22xer3alc',
    name: 'templateTheme',
    display: true,
    hidden: false,
    _fc_drag_tag: 'input',
    col: {
      span: 24,
    },
  },
  {
    type: 'TinymceEditor',
    field: 'templateContent',
    title: '邮件内容',
    $required: true,
    props: {
      placeholder: '请输入邮件内容',
      options: {
        height: 400,
      },
    },
    _fc_id: 'id_Fwn2mx22xuazaoc',
    name: 'templateContent',
    display: true,
    hidden: false,
    _fc_drag_tag: 'TinymceEditor',
    col: {
      span: 24,
    },
  },
  {
    type: 'input',
    field: 'desc',
    title: '备注',
    $required: false,
    props: {
      type: 'textarea',
      placeholder: '请输入备注',
    },
    _fc_id: 'id_Fwn9mc22xutzaoc',
    name: 'desc',
    display: true,
    hidden: false,
    _fc_drag_tag: 'textarea',
    col: {
      span: 24,
    },
  },
]
